require "event_editor/gadgets/switch_button"
require 'gadgets/combobox'

module EventEditor
  module Conditions
    class Dir < Gtk::VBox
      DIRECTIONS = [['Up', 0], ['Right', 1], ['Down',2], ['Left', 3]]
      def initialize(base, model)
        super()
        @model = model

        @@event_combobox = ::Gadgets::Combobox.new(@model.event_select_list(:all), [String, Integer])
        
        box = Gtk::HBox.new
        box.pack_start(@@event_combobox, false, false)
        @@dir_combobox = ::Gadgets::Combobox.new(DIRECTIONS, [String, Integer])
        box.pack_start(@@event_combobox, false, false)
        box.pack_start(@@dir_combobox, false, false)
        
        self.add(box)
      end
      
      def commands
        return ['dir', @@event_combobox.selected_data, @@dir_combobox.selected_data]
      end
      
      def self.load(command)
        @@event_combobox.select(command[1])
        @@dir_combobox.select(command[2])
      end
      
      def self.command_to_s(model, args)
        arr = ['Up', 'Right', 'Down', 'Left']
        
        name = '[<span color="red">invalid</span>]'
        model.event_select_list.each do |t|
          if t[1] == args[1]
            name = "[ " + t[0] + " ]"
            break
          end
        end
        
        s = "<b>Direction:</b> #{name} faces #{arr[args[2].to_i]}"
        
        return s
      end
    end
  end
end